#include <bits/stdc++.h>
// 2025/01/19
// tag: 
// Author: Zhang Muen
using namespace std;

struct Gang{
    int position, name, level, contribution;
} absi2011[111];

int n;
char name[111][31];
map<string, int> toint = {{"BangZhu", 1}, {"FuBangZhu", 2}, {"HuFa", 3}, {"ZhangLao", 4}, {"TangZhu", 5}, {"JingYing", 6}, {"BangZhong", 7}};
map<int, string> tostring = {{1, "BangZhu"}, {2, "FuBangZhu"}, {3, "HuFa"}, {4, "ZhangLao"}, {5, "TangZhu"}, {6, "JingYing"}, {7, "BangZhong"}};


bool cmp(const Gang &a, const Gang &b){
    if (a.contribution != b.contribution)
        return a.contribution > b.contribution;
    return a.name < b.name;
}

bool cmp2(const Gang &a, const Gang &b)
{
    if (a.position != b.position)
        return a.position < b.position;
    if (a.level != b.level)
        return a.level > b.level;
    return a.name < b.name;
}

inline int toposition(int x){
    if (x == 1)
        return 1;
    else if (x == 2 || x == 3)
        return 2;
    else if (x == 4 || x == 5)
        return 3;
    else if (6 <= x && x <= 9)
        return 4;
    else if (10 <= x && x <= 16)
        return 5;
    else if (17 <= x && x <= 41)
        return 6;
    return 7;
}

signed main()
{
    cin >> n;
    for (int i = 1; i <= n; i++){
        string position;
        cin >> name[i] >> position >> absi2011[i].contribution >> absi2011[i].level;
        absi2011[i].name = i, absi2011[i].position = toint[position];
    }
    sort(absi2011 + 1, absi2011 + n + 1, cmp);
    int p = 4;
    for (int i = 1; i <= n; i++)
    {
        if (absi2011[i].position == 1 || absi2011[i].position == 2)
            continue;
        absi2011[i].position = toposition(p++);
    }
    sort(absi2011 + 1, absi2011 + n + 1, cmp2);
    for (int i = 1; i <= n; i++)
        cout << name[absi2011[i].name] << " " << tostring[absi2011[i].position] << " " << absi2011[i].level << endl;
    return 0;
}